import ArrayList from '@ohos.util.ArrayList'

export class WeatherIndex {
  isInit: boolean = false

  /**
   * 请求码
   */
  code: string
  /**
   * 当前API的最近更新时间
   */
  updateTime: string
  /**
   * 天气指数
   */
  daily: ArrayList<DailyForIndex>

  static transition(dto: any): WeatherIndex {
    let weatherIndex = new WeatherIndex()
    weatherIndex.code = dto.code
    weatherIndex.updateTime = dto.updateTime
    weatherIndex.daily = new ArrayList()
    for (const index in dto.daily) {
      weatherIndex.daily.add(DailyForIndex.transition(dto.daily[index]))
    }
    return weatherIndex
  }
}

export class DailyForIndex {
  // "date": "2023-12-06",
  // "type": "1",
  // "name": "运动指数",
  // "level": "2",
  // "category": "较适宜",
  // "text": "天气较好，无雨水困扰，较适宜进行各种运动，但因气温较低，在户外运动请注意增减衣物。"

  date: string
  type: string
  name: string
  level: string
  category: string
  text: string

  static transition(dto: any): DailyForIndex {
    let dailyForIndex = new DailyForIndex()
    dailyForIndex.date = dto.date
    dailyForIndex.type = dto.type
    dailyForIndex.name = dto.name
    dailyForIndex.level = dto.level
    dailyForIndex.category = dto.category
    dailyForIndex.text = dto.text ?? "未知"
    return dailyForIndex
  }
}